package org.giovanolli.mumi.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;

/**
 * The Class DateUtils.
 */
public abstract class DateUtils {

	/** The Constant defaultLocale. */
	private static final Locale defaultLocale = new Locale("es");

	/**
	 * Gets the simple formatted date.
	 * 
	 * @param date
	 *            the date
	 * @return the simple formatted date
	 */
	public static String getSimpleFormattedDate(Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy", defaultLocale);
		String rv = formatter.format(date);
		return rv;
	}

	/**
	 * Gets the specific dates in range.
	 * 
	 * @param startDate
	 *            the start date
	 * @param endDate
	 *            the end date
	 * @param days
	 *            the days
	 * @return the specific dates in range
	 */
	public static List<Date> getSpecificDatesInRange(Date startDate, Date endDate, List<Integer> days) {
		List<Date> rv = new ArrayList<Date>();
		Calendar cal = new GregorianCalendar();
		cal.setTime(startDate);
		do {
			if (days.contains(String.valueOf(cal.get(Calendar.DAY_OF_WEEK)))) {
				rv.add(cal.getTime());
			}

			cal.add(Calendar.DAY_OF_MONTH, 1);
		} while (!cal.getTime().after(endDate));
		return rv;
	}

	/**
	 * The main method.
	 * 
	 * @param args
	 *            the arguments
	 */
	public static void main(String[] args) {
		Calendar c = new GregorianCalendar();
		Date start = c.getTime();
		c.add(Calendar.DAY_OF_MONTH, 45);
		Date end = c.getTime();
		// System.out.println(getSpecificDatesInRange(start,end,new Integer[]{1,4}));
	}
}
